package logic.operation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JProgressBar;
import javax.swing.Timer;

import org.apache.log4j.Logger;

import logic.file.IDirectory;
import logic.file.IFile;

/**
 * Klasa rozszerzająca klasę AbstractFileOperation, 
 * tak by obslużyć operacje o charakterrze source -> target: przeniesienie i kopiowanie plików
 * @author Marcin
 *
 */
//Poprzez dziedziczenie z AbstractObservableFileOperation każda operacja transferu ma zaimplementowany interfejs Observable
public abstract class AbstractTransferOperation extends AbstractObservableFileOperation {
	
	private static Logger logger = Logger.getLogger(AbstractTransferOperation.class);
	//TODO przeniesienie części odpowiedzialności do klasy AbstractObservableFileOperation
	public static int STANDARD_INTERVAL_FOR_TIMER = 100;
	
	protected IDirectory destination;
	
  	protected ByteCounter byteCounter = new ByteCounter();
  	
  	protected Timer timer;
  	
  	protected ActionListener timerAction;
  	
  	protected int totalSize;
  	
	
	public AbstractTransferOperation(List<IFile> files , IDirectory destination, IOperationObserver observer) {
		super(files, observer);
		this.destination = destination;
	}
	
	public AbstractTransferOperation() { }
	
	public void setDestination(IDirectory destination) {
		this.destination = destination;
	}
	
	protected class TimerAction implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			logger.debug("logged prog:" + ( (double) byteCounter.getCurrentVal() ) / totalSize );
			notifyObservers( ( (double) byteCounter.getCurrentVal() ) / totalSize, byteCounter.getCurrentFile() );
		}
		
	}

}
